<p>This rule reports syntax errors in Spring Expression Language (<code>SpEL</code>) expressions and property placeholders. It verifies that every
<code>SpEL</code> expression and property placeholder is properly closed and that the content of each expression or placeholder is syntactically
correct.</p>
<h2>Why is this an issue?</h2>
<p>Only the Spring framework, not the Java compiler, parses <code>SpEL</code> expression inside Spring annotations. This means that the Java compiler
does not detect invalid <code>SpEL</code> expressions during compile time. They will cause exceptions during runtime instead, or even fail silently
when Spring interprets the expression as a simple string literal.</p>
<h3>Exceptions</h3>
<p>This rule reports syntactical errors in <code>SpEL</code> expressions but does not consider semantic errors, such as unknown identifiers or
incompatible operand data types.</p>
<h2>How to fix it</h2>
<p>Correct the syntax error in the SpEL expression.</p>
<h3>Code examples</h3>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
@Value("#{systemProperties['user.region'}") // Noncompliant: unclosed "["
private String region;
</pre>
<pre data-diff-id="2" data-diff-type="noncompliant">
@Value("#{'${listOfValues}' split(',')}") // Noncompliant: missing operator
private List&lt;String&gt; valuesList;
</pre>
<pre data-diff-id="3" data-diff-type="noncompliant">
@Value("#{T(java.lang.Math).random() * 64h}") // Noncompliant: invalid number
private Double randPercent;
</pre>
<pre data-diff-id="4" data-diff-type="noncompliant">
@Query("SELECT u FROM User u WHERE u.status = :#{#status+}") // Noncompliant: missing operand for "+"
List&lt;User&gt; findUsersByStatus(@Param("status") String status);
</pre>
<pre data-diff-id="5" data-diff-type="noncompliant">
@Value("${myapp.!prop}") // Noncompliant: property key contains an exclamation mark "!"
private String myProperty;
</pre>
<pre data-diff-id="6" data-diff-type="noncompliant">
@Value("${my.property:#{1**1}}") // Noncompliant: invalid SpEL expression "1**1"
private Integer myValue;
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
@Value("#{systemProperties['user.region']}") // Compliant
private String region;
</pre>
<pre data-diff-id="2" data-diff-type="compliant">
@Value("#{'${listOfValues}'.split(',')}") // Compliant
private List&lt;String&gt; valuesList;
</pre>
<pre data-diff-id="3" data-diff-type="compliant">
@Value("#{T(java.lang.Math).random() * 100.0}") // Compliant
private Double randPercent;
</pre>
<pre data-diff-id="4" data-diff-type="compliant">
@Query("SELECT u FROM User u WHERE u.status = :#{#status+42}") // Compliant
List&lt;User&gt; findUsersByStatus(@Param("status") String status);
</pre>
<pre data-diff-id="5" data-diff-type="compliant">
@Value("${myapp.prop}") // Compliant
private String myProperty;
</pre>
<pre data-diff-id="6" data-diff-type="compliant">
@Value("${my.property:#{1*1}}") // Compliant
private Integer myValue;
</pre>
<h2>Resources</h2>
<h3>Documentation</h3>
<ul>
  <li> Spring Framework Documentation - <a href="https://docs.spring.io/spring-framework/reference/core/expressions.html">Spring Expression Language
  (SpEL)</a> </li>
</ul>

